package org.vgou.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 
 * Copyright (c) 2011, vgou All rights reserved.
 * 
 * @since Nov 27, 2011
 * @author <a href="mailto:jason.hxx@gmail.com">jason</a>
 * @version Id: User.java Nov 27, 2011
 * @comment 用户实体类
 * 
 */
@Entity
// 更新一个对象时,会生成动态SQL,当属性值发生变化时，才会包含到UPDATE语句中
@org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
@Table(name = "user")
public class User implements Serializable {

	private static final long serialVersionUID = 7463081575568392380L;

	/** 唯一主键 * */
	@Id
	@GeneratedValue
	@Column(name = "id", length = 19)
	private long id;
	
	/** 用户账号 **/
	@Column(name = "username", nullable=false)
	private String username;
	
	/** 用户密码 **/
	@Column(name = "password", nullable=false)
	private String password;

	/** 账号状态  1 未激活  2 已激活  3 屏蔽 **/
	@Column(name = "status", nullable=false)
	private int status = 1;
	
	/** 用户类型  1 普通用户  2 商家用户 **/
	@Column(name="type", nullable=false)
	private int type = 1;
	
	/** 所处地区 **/
	@ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
	@JoinColumn(name="locationid")
	private Location location;

	/** 收货地址集合 **/
	@OneToMany(mappedBy="user", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	private Set<ShippingAddress> shippingAddress = new HashSet<ShippingAddress>();
	
	public User() {
		super();
	}

	public User(long id, String username, String password, int status,
			int type, Location location) {
		super();
		this.id = id;
		this.username = username;
		this.password = password;
		this.status = status;
		this.type = type;
		this.location = location;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public Set<ShippingAddress> getShippingAddress() {
		return shippingAddress;
	}

	public void setShippingAddress(Set<ShippingAddress> shippingAddress) {
		this.shippingAddress = shippingAddress;
	}
	
}
